{% extends "zato/index.html" %}
{% load extras %}

{% block html_title %}Redis connections{% endblock %}

{% block "extra_css" %}
    <link rel="stylesheet" type="text/css" href="/static/css/jquery.alerts.css">
    {% if items %}
        {% include "zato/css-titlebar-padding.html" %}
    {% endif %}
{% endblock %}

{% block "extra_js" %}

    {% comment %} jQuery {% endcomment %}
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.tablesorter.min.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.cookie.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.alerts.min.js"></script>

    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/js/common.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/js/outgoing/redis/index.js"></script>

    <script nonce="{{ CSP_NONCE }}">
    $.fn.zato.data_table.get_columns = function() {
        return [
            '_numbering',
            '_selection',

            {% comment %} 1 {% endcomment %}
            'name',
            '_is_active',
            '_host',

            {% comment %} 2 {% endcomment %}
            '_port',
            '_db',
            '_use_redis_sentinels',

            {% comment %} 3 {% endcomment %}
            'redis_sentinels',
            '_remote_commands',
            '_change_password',

            {% comment %} 4 {% endcomment %}
            'redis_sentinels_master',
            '_edit',
            '_delete',

            {% comment %} 5 {% endcomment %}
            'use_redis_sentinels',
            'id',
            'is_active',

            {% comment %} 6 {% endcomment %}
            'host',
            'port',
            'db',
        ]
    }
    </script>

{% endblock %}

{% block "content" %}
<h2 class="zato">Redis connections</h2>

{% if not zato_clusters %}
    {% include "zato/no-clusters.html" %}
{% else %}

    <div id="user-message-div" style='display:none'><pre id="user-message" class="user-message"></pre></div>

    {% include "zato/search-form.html" with page_prompt="Show connections"%}

    {% if cluster_id %}

        <div id="markup">
            <table id="data-table">
                <thead>
                    <tr class='ignore'>
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>

                        {% comment %} 1 {% endcomment %}
                        <th><a href="#">Name</a></th>
                        <th><a href="#">Active</a></th>
                        <th><a href="#">Host</a></th>

                        {% comment %} 2 {% endcomment %}
                        <th><a href="#">Port</a></th>
                        <th><a href="#">DB</a></th>
                        <th><a href="#">Sentinels enabled</a></th>

                        {% comment %} 3 {% endcomment %}
                        <th class='ignore'>&nbsp;</th>
                        <th></th>
                        <th></th>

                        {% comment %} 4 {% endcomment %}
                        <th class='ignore'>&nbsp;</th>
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>

                        {% comment %} 5 {% endcomment %}
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>

                        {% comment %} 6 {% endcomment %}
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>

                </thead>

                <tbody>
                {% if items %}
                {% for item in items %}
                    <tr class="{% cycle 'odd' 'even' %}" id='tr_{{ item.id }}'>
                        <td class='numbering'>&nbsp;</td>
                        <td class="impexp"><input type="checkbox" /></td>

                        {% comment %} 1 {% endcomment %}
                        <td>{{ item.name }}</td>
                        <td>{{ item.is_active|yesno:'Yes,No' }}</td>
                        <td>{{ item.host|no_value_indicator }}</td>

                        {% comment %} 2 {% endcomment %}
                        <td>{{ item.port|no_value_indicator }}</td>
                        <td>{{ item.db|no_value_indicator }}</td>
                        <td>{{ item.use_redis_sentinels|yesno:'Yes,No' }}</td>

                        {% comment %} 3 {% endcomment %}
                        <td class='ignore'>{{ item.redis_sentinels }}</td>
                        <td><a href="{% url "kvdb-remote-command" %}?cluster={{ cluster_id|default:'' }}">Remote commands</a></td>
                        <td><a href="javascript:$.fn.zato.data_table.change_password('{{ item.id }}')">Change password</a></td>

                        {% comment %} 4 {% endcomment %}
                        <td class='ignore'>{{ item.redis_sentinels_master }}</td>
                        <td><a href="javascript:$.fn.zato.outgoing.redis.edit('{{ item.id }}')">Edit</a></td>
                        <td>
                            {% if item.name != "default" %}
                                <a href="javascript:$.fn.zato.outgoing.redis.delete('{{ item.id }}')">Delete</a>
                            {% endif %}
                        </td>

                        {% comment %} 5 {% endcomment %}
                        <td class='ignore'>{{ item.use_redis_sentinels }}</td>
                        <td class='ignore item_id_{{ item.id }}'>{{ item.id }}</td>
                        <td class='ignore'>{{ item.is_active }}</td>

                        {% comment %} 6 {% endcomment %}
                        <td class='ignore'>{{ item.host|default:'' }}</td>
                        <td class='ignore'>{{ item.port|default:'' }}</td>
                        <td class='ignore'>{{ item.db|default:'' }}</td>

                    </tr>
                {% endfor %}
                {% else %}
                    <tr class='ignore'>
                        <td colspan='22'>No results</td>
                    </tr>
                {% endif %}

                </tbody>
            </table>
        </div>

{% include "zato/paginate/action-panel.html" %}

        <div id="create-div" class='data-popup ignore'>
            <div class="bd">
                <form novalidate action="{% url "out-redis-create" %}" method="post" id="create-form">

                    <table class="form-data">

                        <!--
                        <tr>
                            <td style="vertical-align:middle;width:17%">
                                <label for="id_name">
                                Name
                                </label>
                            </td>
                            <td>
                                {{ create_form.name }}

                                |

                                <label>
                                Active
                                {{ create_form.is_active }}
                                </label>

                            </td>
                        </tr>
                        -->

                        <tr>
                            <td>
                                <label for="id_address">
                                Host
                                </label>
                            </td>
                            <td>
                                {{ create_form.host }}

                                |

                                <label>
                                Port
                                {{ create_form.port }}
                                </label>

                                |

                                <label>
                                DB
                                {{ create_form.db }}
                                </label>

                            </td>
                        </tr>
                        <tr>
                            <td>Sentinels</td>
                            <td>

                                <label>
                                Enabled
                                {{ create_form.use_redis_sentinels }}
                                </label>

                                |

                                <label>
                                Master
                                {{ create_form.redis_sentinels_master }}
                                </label>

                                <br/>
                                Nodes
                                <br/>
                                <label>
                                {{ create_form.redis_sentinels }}
                                </label>

                            </td>
                        </tr>

                        <tr>
                            <td colspan="2" style="text-align:right">
                                <input type="submit" value="OK" />
                                <button type='button' onclick='javascript:$.fn.zato.data_table.close(this)'>Cancel</button>
                            </td>

                        </tr>
                    </table>

                    <input type="hidden" id="cluster_id" name="cluster_id" value="{{ cluster_id }}" />
                </form>
            </div>
        </div>

        <div id="edit-div" class='data-popup ignore'>
            <div class="bd">
                <form novalidate action="{% url "out-redis-edit" %}" method="post" id="edit-form">

                    <table class="form-data">

                        <!--
                        <tr>
                            <td style="vertical-align:middle;width:17%">
                                <label for="id_name">
                                Name
                                </label>
                            </td>
                            <td>
                                {{ edit_form.name }}

                                |

                                <label>
                                Active
                                {{ edit_form.is_active }}
                                </label>

                            </td>
                        </tr>
                        -->

                        <tr>
                            <td>
                                <label for="id_address">
                                Host
                                </label>
                            </td>
                            <td>
                                {{ edit_form.host }}

                                |

                                <label>
                                Port
                                {{ edit_form.port }}
                                </label>

                                |

                                <label>
                                DB
                                {{ edit_form.db }}
                                </label>

                            </td>
                        </tr>
                        <tr>
                            <td>Sentinels</td>
                            <td>

                                <label>
                                Enabled
                                {{ edit_form.use_redis_sentinels }}
                                </label>

                                |

                                <label>
                                Master
                                {{ edit_form.redis_sentinels_master }}
                                </label>

                                <br/>
                                Nodes
                                <br/>
                                <label>
                                {{ edit_form.redis_sentinels }}
                                </label>

                            </td>
                        </tr>

                        <tr>
                            <td colspan="2" style="text-align:right">
                                <input type="submit" value="OK" />
                                <button type='button' onclick='javascript:$.fn.zato.data_table.close(this)'>Cancel</button>
                            </td>

                        </tr>
                    </table>

                    <input type="hidden" id="id_edit-cluster_id" name="cluster_id" value="{{ cluster_id }}" />
                    <input type="hidden" id="id_edit-name" name="name" value="default" />
                    <input type="hidden" id="id_edit-is_active" name="is_active" value="true" />
                    <input type="hidden" id="id_edit-id" name="id" />
                </form>
            </div>
        </div>

        <div id="change_password-div" class='data-popup ignore'>
            <div class="bd">
                <form novalidate action="{% url "out-redis-change-password" %}" method="post" id="change_password-form">
                    <table class="form-data">
                        <tr>
                            <td style="vertical-align:middle; width:10%">Name</td>
                            <td id="change-password-name"></td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">Password</td>
                            <td>{{ change_password_form.password1 }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">Confirm password</td>
                            <td>{{ change_password_form.password2 }}
                                <input type="hidden" id="id_change_password-id" name="id" />
                                <input type="hidden" id="id_change_password-cluster_id" name="cluster_id" value='{{ cluster_id}}' />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" style="text-align:right">
                                <input type="submit" value="OK" />
                                <button type='button' onclick='javascript:$.fn.zato.data_table.close(this)'>Cancel</button>
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
    {% endif %}


{% endif %}{% comment %}not zato_clusters{% endcomment %}

{% endblock %}
